﻿using System.Data;
using System.Drawing;
using System;
using System.Collections.Generic;

namespace Home.Haushalt.Lib.Element
{
    /// <summary>
    /// 
    /// </summary>
    [ElementExtension("Property")]
    public class Group : ElementBase
    {
        #region CONSTANTS
        public new static readonly Type ElementType = typeof(Group);

        /// <summary></summary>
        public class Fields
        {
            public const string Id = ELEMENTPROPERTY_ID;
            public const string Name = "n";
            public const string ParentId = "p";
            public const string PostenGruppeIds = "t";

            public const string UnboundFullName = "FullName";
        }
        #endregion CONSTANTS

        /// <summary>
        /// 
        /// </summary>
        public Group() : base() { }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="parentDataRow"></param>
        public Group(DataRow parentDataRow) : base(parentDataRow) { }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public override Dictionary<string, object> CalculateUnboundFields()
        {
            Dictionary<string, object> result = new Dictionary<string, object>();

            if (CheckColumnsInRow(Fields.ParentId, Fields.Name))
            {

                string suffix = "";
                if (Row[Fields.ParentId].ToInt() > 0)
                {
                    suffix = DAO.GetPropertyAtId(Group.ElementType, Row[Fields.ParentId].ToInt(), Fields.Name).ToString() + ": ";
                }
                string fullName = suffix + Row[Fields.Name].ToString();

                result.Add(Fields.UnboundFullName, fullName);
            }

            return result;
        }
    }
}
